package cn.water.luban.demo.order.dubbo;

import cn.water.demo.luban.protocol.cart.param.CartDeleteParam;
import cn.water.luban.demo.cart.api.CartApi;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;

public class ConsumerClient {
    public static void main(String[] args) {
        CartApi cartApi = getProxy();
        cartApi.cartDelete(new CartDeleteParam());
    }

    //创建一个连接provider的代理对象
    private static CartApi getProxy() {
        DubboBootstrap client = DubboBootstrap.getInstance();
        client.application("order-consumer");
//        ProtocolConfig protocolConfig = new ProtocolConfig();
//        protocolConfig.setPort(-1);
//        protocolConfig.setName("dubbo");
//        client.protocol(protocolConfig);
        RegistryConfig registryConfig = new RegistryConfig("nacos://localhost:8848");
        client.registry(registryConfig);
        ReferenceConfig<CartApi> referenceConfig = new ReferenceConfig<CartApi>();
        referenceConfig.setInterface(CartApi.class);
        client.reference(referenceConfig);
        CartApi cartApiProxy = referenceConfig.get();
        System.out.println("拿到代理类:"+cartApiProxy.getClass().getName());
        return cartApiProxy;
    }
}
